package logic

import (
	"DataSrv/global/model"
	"context"
	"gorm.io/gorm"

	"DataSrv/data"
	"DataSrv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassesAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewClassesAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassesAddLogic {
	return &ClassesAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ClassesAddLogic) ClassesAdd(in *data.ClassesAddRequest) (*data.ClassesAddResponse, error) {
	// todo: add your logic here and delete this line
	var classes model.Classes
	classes.Name = in.Name
	model.DB.Create(&classes)
	for _, id := range in.VideoIds {
		model.DB.Updates(&model.Video{
			Model: gorm.Model{
				ID: uint(id),
			},
			ClassesId: int(classes.ID),
		})
	}
	return &data.ClassesAddResponse{}, nil
}
